package com.fyl.leetcode.doublePointer;

import java.util.Arrays;

/**
 * @author:fyl
 * @date 2021/8/26 9:46
 * @Modified By:
 * @Modified Date:
 * @Description:
 */
public class RemoveElement {
    //暴力法
    public int removeElement(int[] nums, int val) {
        int size = nums.length;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == val) {
                for (int j = i + 1; j < nums.length; j++) {
                    nums[j - 1] = nums[j];
                }
                i--;
                size--;
            }
        }
        return size;
    }

    //双指针
    public int removeElement1(int[] nums, int val) {
        int slow = 0;
        for (int fast = 0; fast < nums.length; fast++) {
            if (nums[fast] != val) {
                nums[slow++] = nums[fast];
            }
        }
        return slow;
    }
}
